﻿//模块描述：    导航管理列表页
//创建人：      
//创建日期：    2010年04月12日 
//修改描述：
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using webnew.Common;
namespace webnew.Systems
{
    public partial class S_navigationList : ListBase
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
           // System.Threading.Thread.Sleep(3000);
            _ListTbName = "Sys_Navigation";                //删除的数据库表名
            _Grdview = grdView;                            //gridview控件
            _DelType = DeleteType.FalseDel;                 //逻辑删除
            _EditSrc = "S_navigationEdit.aspx";
            btnExcelVisble = false;
            #region 传递参数，把控件值赋值给参数
            _SrcPrams = "&NavType=" + ddlType.SelectedValue + "&NavName=" + txtName.Text + "&RecordCount=" + AspNetPager1.RecordCount + "&CurrentPageIndex=" + AspNetPager1.CurrentPageIndex;
            #endregion
            //SetPageWidth = "1500px";          
            this.Form.DefaultButton=btnSearch.UniqueID;// 按回车键响应检索按钮事件

            if (!IsPostBack)
            {            //编辑的路径
                SetTitle(true, "后台管理>>导航管理");             //标题
                #region 接收参数，并赋值给检索控件
                if (Request.QueryString["NavType"] != null) ddlType.SelectedValue = Request.QueryString["NavType"].ToString();
                if (Request.QueryString["NavName"] != null) txtName.Text = Request.QueryString["NavName"].ToString();
                //记录分页页数 需传递总条数和当前页数 
                if (Request.QueryString["RecordCount"] != null) AspNetPager1.RecordCount = Convert.ToInt32(Request.QueryString["RecordCount"]);
                if (Request.QueryString["CurrentPageIndex"] != null) AspNetPager1.CurrentPageIndex = Convert.ToInt32(Request.QueryString["CurrentPageIndex"]);
                #endregion
                AspNetPager1_PageChanged(null, null);
              
            }

        }

        //检索
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1_PageChanged(null, null);
        }

        //删除
        protected override void _Del()
        {
            //----------系统日志model

            Model.Sys_LogInfo modelLog = new webnew.Model.Sys_LogInfo();
            modelLog.UserID = UserInfor.Id;                  //用户ID
            modelLog.IP = new BLL.Sys_Log().GetUserIP(System.Web.HttpContext.Current.Request);  //IP
            modelLog.Module = new BLL.Sys_Navigation().GetModuleName(this.GetType().BaseType.Name);   //模块名
            modelLog.CreateDate = DateTime.Now;           //创建时间

            string error = "";                   //获取错误信息

            try
            {
                base._Del();
            }
            catch (Exception e)
            {
                error = e.ToString();
            }
            finally
            {
                //添加一条系统日志
                new BLL.Sys_Log().AddSysLog(error, "删除", modelLog, "导航", "导航，名称为" + GetNames("naviname", _ListTbName));
            }
            AspNetPager1_PageChanged(null, null);
            
        }

        //分页控件页翻页事件
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            //System.Text.StringBuilder _conditon = new System.Text.StringBuilder();  //分页的查询的条件 
            //_conditon.Append(" isdel<>1 and NaviName like '%" + txtName.Text.Trim().Replace("'", "") + "%' ");
            //if (ddlType.SelectedValue != "全部") _conditon.Append(" and ispage= " + ddlType.SelectedValue + "");  
            //AspNetPager1.RecordCount = new BLL.Sys_Navigation().GetCount(_conditon.ToString());
            //Common.CommonHelper.DataGrdBind(_Grdview,new BLL.Sys_Navigation().GetPageList("*",_conditon.ToString(),_Grdview.PageSize,AspNetPager1.CurrentPageIndex,_ListTbName,"ParentID,Sort,id",true));
            System.Text.StringBuilder _conditon = new System.Text.StringBuilder();  //分页的查询的条件 
            System.Text.StringBuilder _Feil = new System.Text.StringBuilder();  //查询的字段
            _Feil.Append(" a.*,(select b.NaviName from Sys_Navigation b where a.ParentID=b.Id) as PraentName ");
            _conditon.Append(" a.isdel<>1 and a.NaviName like '%" + txtName.Text.Trim().Replace("'", "") + "%' ");
            _conditon.Append(" and (select b.NaviName from Sys_Navigation b where a.ParentID=b.Id)   like '%" + txtPraent.Text + "%' ");
            if (ddlType.SelectedValue != "全部") _conditon.Append(" and a.ispage= " + ddlType.SelectedValue + "");
            AspNetPager1.RecordCount = new BLL.Sys_Navigation().GetCount(" Sys_Navigation a ",_conditon.ToString());
            Common.CommonHelper.DataGrdBind(grdView, new BLL.Sys_Navigation().GetPageList(_Feil.ToString(), _conditon.ToString(), grdView.PageSize, AspNetPager1.CurrentPageIndex, " Sys_Navigation a ", "a.ParentID,a.NaviName,a.id", true));
      


        }
        
        ////根据其父ID获取其父级名称 -----gridview控件的第四列
        //public string GetParentName(string ParentID)
        //{
        //    Model.Sys_NavigationInfo parentModel = new BLL.Sys_Navigation().GetList(ParentID);
        //    return object.Equals(parentModel.NaviName, null) ? "空" : parentModel.NaviName;
        //}

        protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //鼠标经过变色
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "GridViewMouseover(this)");
                e.Row.Attributes.Add("onmouseout", "GridViewMouseout(this)");
                e.Row.Attributes.Add("onclick", "GridViewonclick(this)");
                CommonHelper.grdCellStyle(e.Row.Cells[3], 80);
                CommonHelper.grdCellStyle(e.Row.Cells[5], 90);
                //备注提示
                e.Row.Cells[5].ToolTip = e.Row.Cells[5].Text == "&nbsp;" ? "" : e.Row.Cells[5].Text;
            }

        }
      /// <summary>
      /// 显示条数下拉框
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            grdView.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            AspNetPager1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            AspNetPager1_PageChanged(null, null);
        }

        ////预览 
        //protected void btnPreview_Click(object sender, EventArgs e)
        //{
        //    //Jscript.OpenWebFowebnewize("../Systems/View_Navgation.aspx",350,450,250,450,true,Page);
        //    ClientScript.RegisterStartupScript(ClientScript.GetType(), "OnPreview", "return OnPreview();");
        //}

      
    }
}
